﻿@using HCMS.Dictionary
@{
    Layout = "~/Views/Shared/_Layout_Pear_Layui.cshtml";
}

@section Styles {

}

<div class="layui-card">
    <div class="layui-card-body layui-current-form">
        <form class="layui-form">
            <div class="layui-form-item">
                <div class="layui-form-item layui-inline">
                    <div class="layui-input-inline layui-form-group">
                        <select id="searchName" name="searchName">
                            <option value="adminName">管理员</option>
                            <option value="url">链接</option>
                            <option value="controllerName">控制器</option>
                            <option value="actionName">方法</option>
                        </select>
                        <input type="text" id="searchKey" placeholder="" class="layui-input layui-form-group-input" autocomplete="off">
                    </div>
                </div>

                <div class="layui-form-item layui-inline">
                    <button type="submit" class="layui-btn" lay-submit lay-filter="btn-query" style="margin-right:4px;">
                        <i class="layui-icon layui-icon-search"></i>
                        查询
                    </button>
                    <button type="reset" class="layui-btn layui-btn-primary" lay-filter="btn-reset">
                        <i class="layui-icon layui-icon-refresh"></i>
                        重置
                    </button>
                </div>
            </div>
        </form>
    </div>
</div>

<div class="layui-card">
    <div class="layui-card-body">
        <table id="tableList" lay-filter="tableList"></table>
    </div>
</div>

<script type="text/html" id="actionBox">
    <vc:menu-a action-names="@(new string[]{"detail"})"></vc:menu-a>
</script>

@section Scripts {
    <script>
        layui.use(['table', 'form', 'jquery', 'util'], function () {
            let table = layui.table;
            let form = layui.form;
            let $ = layui.jquery;
            let util = layui.util;

            loadList();
            search();
            tableActionTool();

            // 列表
            function loadList() {
                table.render({
                    elem: '#tableList',
                    url: '/adminactionlogs/list/',
                    method: 'post',
                    where: getQueryParams(),
                    height: 'full',
                    page: true,
                    cols: [[
                        { field: 'id', title: 'ID', width: 80 },
                        { field: 'createTime', title: '操作 时间', align: 'center', width: 160, templet: function (d) { return util.toDateString(d.createTime); } },
                        { field: 'adminName', title: '管理员', width: 100 },
                        { field: 'ip', title: 'IP', width: 180 },
                        { title: '操作', toolbar: '#actionBox', width: 100, style: 'height: 40px;' },
                        { field: 'url', title: '访问链接', width: 260 },
                        { field: 'controllerName', title: '控制器 名称', width: 150 },
                        { field: 'actionName', title: '方法 名称', width: 150 },
                        { field: 'executionTime', title: '消耗 时间', width: 100 }
                    ]],
                    skin: 'line',
                    toolbar: '#toolbar',
                    defaultToolbar: [{
                        title: '刷新',
                        layEvent: 'refresh',
                        icon: 'layui-icon-refresh',
                    }, 'filter']
                });
            }

            // 搜索
            function search() {
                form.on('submit(btn-query)', function (data) {
                    table.reload('tableList', {
                        where: getQueryParams(),
                        page: {
                            curr: 1
                        }
                    });
                    return false;   // 阻止默认 form 跳转
                });
            }

            // 搜索条件
            function getQueryParams() {
                return {
                    searchName: $('#searchName').val(),
                    searchKey: $('#searchKey').val()
                };
            }

            // 表格项 操作按钮
            function tableActionTool() {
                table.on('tool(tableList)', function (obj) {
                    switch (obj.event) {
                        case 'detail': detail(obj); break;
                    }
                });

                // 详情
                function detail(obj) {
                    layer.open({
                        type: 2,
                        title: '查看 ID：' + obj.data['id'],
                        area: ['85%', '85%'],
                        content: '/adminactionlogs/detail/?id=' + obj.data['id']
                    });
                }
            }
        });
    </script>
}